<template>
    <!-- 新增和修改 -->
    <div class="modal fade" id="addhealthinteract" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">
                {{modaltitle}}</h4>
                </div>
                <div class="fail cbafter" v-show="healthinteractsavedata.verifyState=='2'">
                    <div class="textdes">
                        <p class="nosuccess">审核未通过！</p>
                        <p>{{healthinteractsavedata.verifySuggestion}}</p>
                    </div>
                </div>
                <div class="changeinfo cbafter">
                    <div class="changeinfo_head cbafter">
                        <span>申请人：{{username}}</span>
                        <span>申请时间：{{applytime}}</span>
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" id="changedocform" v-on:submit.prevent="addhealthinteractsave">
                        <div class="form-group">
                            <label class="col-md-3 control-label">互动标题 :</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" v-model="healthinteractsavedata.interactionTitle" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">开始时间 :</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" id="start" v-model="healthinteractsavedata.interactionBeginTime" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">结束时间 :</label>
                            <div class="col-md-4">
                                <input type="text" class="form-control" id="end" v-model="healthinteractsavedata.interactionEndTime" required />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">互动专家 :</label>
                            <div class="col-md-8">
                                <div id="zhuguanyis">
                                    <input type="hidden" class="form-control" placeholder="" v-model="healthinteractsavedata.interactionUser">
                                    <input type="text" class="form-control" v-model="healthinteractsavedata.interactionUserName" required>
                                    <div class="yishenglist">
                                        <p @click="mayclick()">清空搜索内容</p>
                                        <p @click="mayclick(item,$event)" v-for="item in  expertlist | filterBy healthinteractsavedata.interactionUserName in 'name'">{{item.name}}</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">专家职称 :</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control" v-model="healthinteractsavedata.interactionUserLevelText" readonly />
                            </div>
                        </div>
                        <div class="form-group save">
                            <button type="submit" class="default ok center">确认</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import Public from 'assets/public.js'
import FileUploadBtn from 'components/FileUploadBtn.vue'
import 'assets/lib/laydate/laydate.js'
import 'assets/lib/laydate/need/laydate.css'
import 'assets/lib/laydate/skins/danlan/laydate.css'
module.exports = {
    data() {
            return {
                healthinteractsavedata: {
                    "interactionBeginTime": "", //互动开始时间
                    "interactionEndTime": "", //互动结束时间
                    "interactionTitle": "", //互动标题
                    "interactionUser": "", //互动专家：医生云端ID
                    "interactionUserLevel": "", //互动专家级别
                    "interactionUserName": "", //互动专家名称
                    "interactionUserLevelText": "",
                },
                expertlist: [],
            }
        },
        components: {
            FileUploadBtn
        },
        props: {
            "username": {
                type: String,
                default: ""
            },
            "applytime": {
                type: String,
                default: ""
            },
            
            "modaltitle": {
                type: String,
                default: ""
            },


        },
        ready() {
            var that = this;
            // 日历插件
            laydate({
                elem: '#start',
                format: 'YYYY-MM-DD hh:mm:ss',
                min: laydate.now(),
                istime: true,
                choose: function(datas) { //选择日期完毕的回调  
                    that.healthinteractsavedata.interactionBeginTime = datas
                }
            });
            laydate({
                elem: '#end',
                format: 'YYYY-MM-DD hh:mm:ss',
                istime: true,
                min: laydate.now(),
                choose: function(datas) { //选择日期完毕的回调  
                    that.healthinteractsavedata.interactionEndTime = datas
                }
            });
            // 获取互动专家列表
            $.when(Public.commonajax("coms.doctorService", "queryDoctorByDoctorName", "[[]]"))
                .done(function(res) {
                    that.expertlist = res.body
                })
        },
        methods: {
            //新增和修改弹框
            addhealthinteract(item) {
                    $("#addhealthinteract").modal("show");
                    if (item) {
                        this.username = item.infoApplyUserName;
                        this.applytime = item.infoApplyTime;
                        this.healthinteractsavedata = item;
                        this.modaltitle = "修改健康互动";
                      

                    } else {
                        this.username = sessionStorage.getItem('userName');
                        this.modaltitle = "新增健康互动";
                        this.uploadfilename = "";
                        this.imgurl = "";
                        $("#imgupload").find('a').addClass('none');
                        this.healthinteractsavedata = {
                            "interactionBeginTime": "", //互动开始时间
                            "interactionEndTime": "", //互动结束时间
                            "interactionTitle": "", //互动标题
                            "interactionUser": "", //互动专家：医生云端ID
                            "interactionUserLevel": "", //互动专家级别
                            "interactionUserName": "", //互动专家名称
                            "interactionUserLevelText": "",
                        };
                        var d = new Date(); //获取今天日期
                        var year = d.getFullYear();
                        var month = d.getMonth() + 1;
                        var date = d.getDate();
                        var hour = d.getHours();
                        var minute = d.getMinutes();
                        var second = d.getSeconds();
                        this.applytime = year + "-" + (month < 10 ? '0' + month : month) + "-" + (date < 10 ? '0' + date : date) + "   " + (hour < 10 ? '0' + hour : hour) + ":" + (minute < 10 ? '0' + minute : minute) + ":" + (second < 10 ? '0' + second : second);
                    }
                },
                //新增和修改保存
                addhealthinteractsave() {
                    var that = this;
                    // if(healthinteractsavedata.lectureAttachFile){
                    //    Public.ajaxPrompt("请上传ppt");
                    //    return
                    // }
                    let stringbegintime1 = that.healthinteractsavedata.interactionBeginTime;
                    let stringbegintime2 = that.healthinteractsavedata.interactionEndTime;
                    let begintime = stringbegintime1.substring(0, 10);
                    let endtime = stringbegintime2.substring(0, 10);
                    if (begintime != endtime) {
                        Public.ajaxPrompt("起始和结束日期请选择同一天");
                        return
                    }
                    let begintimecuo =  Date.parse(new Date(stringbegintime1));
                    let endtimecuo = Date.parse(new Date(stringbegintime2));
                    if (begintimecuo > endtimecuo) {
                        Public.ajaxPrompt("起始日期不能大于结束日期");
                        return
                    }
                    $.when(Public.commonajax("coms.healthInteractionService", "saveHealthInteraction", "[" + JSON.stringify(this.healthinteractsavedata) + "]"))
                        .done(function(res) {
                            if (res.code == 200) {
                                Public.ajaxPrompt("提交成功");
                                $("#addhealthinteract").modal("hide");

                                that.$dispatch('healthinteractsave');
                            }

                        })
                },
                // 搜索医生下拉框选中后赋值给input
                mayclick(item, event) {
                    console.log(item);
                    if (item) {
                        this.healthinteractsavedata.interactionUser = item.doctorId;
                        this.healthinteractsavedata.interactionUserName = item.name;
                        this.healthinteractsavedata.interactionUserLevel = item.level;
                        this.healthinteractsavedata.interactionUserLevelText = item.levelText;

                    } else {
                        this.healthinteractsavedata.interactionUser = "";
                        this.healthinteractsavedata.interactionUserName = "";
                        this.healthinteractsavedata.interactionUserLevel = "";
                        this.healthinteractsavedata.interactionUserLevelText = "";
                    }
                    $(".yishenglist").hide();

                },
        },
        events: {

            //上传文件返回的数据
            'servicefileId' (data) {
                this.healthinteractsavedata.lectureAttachFile = data
            },


        },
}
$(function() {
    // 搜索位置主管医生的下拉
    $("#zhuguanyis").find('input').on('click', function(event) {
        event.preventDefault();
        $(".yishenglist").show();
    });
})
</script>
<style scoped>
#zhuguanyis {
    position: relative;
    display: inline-block;
}

#zhuguanyis .yishenglist {
    position: absolute;
    display: none;
    top: 32px;
    z-index: 9;
    width: 172px;
    height: 200px;
    overflow: auto;
    -webkit-box-shadow: 0 0 10px rgba(230, 230, 230, .9);
    -moz-box-shadow: 0 0 10px rgba(230, 230, 230, .9);
    box-shadow: 0 0 10px rgba(230, 230, 230, .9);
    background: #fff;
    border-radius: 0 0 10px 10px;
    padding: 10px
}

#zhuguanyis .yishenglist p {
    line-height: 26px;
    height: 26px;
    margin-top: 5px;
    background: #f1f1f1;
    padding-left: 10px;
    padding-top: 0;
}

#zhuguanyis .yishenglist p:nth-child(1) {
    background: #1dc499;
    color: #fff
}
</style>
